<? require("core/base.php"); ?>
	<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
	<html>
	<head>
	<title>uptime</title>
	<link href="files/main.css" rel="stylesheet" type="text/css">
	</head>

	<body>
	<table width="800" border="0" cellspacing="0" cellpadding="0">
  	<tr>
    	<td><a href="index.php"><img src="img/hdr.png" alt="uptime" width="800" height="100" hspace="0" vspace="0" border="0"></a></td>
  	</tr>
  	<tr>
    	<td valign="top" class="fons33"><?optionBar();?></td>
  	</tr>
  	<tr>
    	<td valign="top" class="fons33b">
      	<table width="100%" border="0" cellspacing="0" cellpadding="8">
        	<tr>
          	<td><p><br>

<? /* 
          	<div style="border: 2px solid #FF8131; background-color: #FFF239; color: black; width: 70%; margin-left: auto; margin-right: auto; font-size: 12px; font-weight: bold; padding: 5px; font-family: Trebuchet MS, Helvetica;">
          		uptime.mansoft.org is undergoing maintenance and will be fully operational in a few hours' time. We apologize for any inconvenience caused.
          	</div>
 */ ?>     

	
	              	<span class="destacat"><br>
              	Machine ranking </span>(order by confirmed uptime)</p>
            	<p><br>
            	</p>
            	<table width="780" border="0" cellspacing="1" cellpadding="1">
              	<tr>
                	<td width="25" class="hdrtaula">Pos</td>
                	<td width="1" class="hdrtaula">&nbsp;</td>
                	<td width="105" class="hdrtaula">Machine</td>
                	<td width="63" class="hdrtaula">Owner</td>
                	<td width="118" class="hdrtaula">Confirmed Uptime</td>
                	<td width="134" class="hdrtaula">Unconfirmed Uptime</td>
                	<td width="105" class="hdrtaula">Avg</td>
                	<td width="126" class="hdrtaula">OS</td>
                	<td width="79" class="hdrtaula">Hardware</td>
              	</tr>

<?
$bd=new bd;

$sQuery="SELECT u.username, u.machine, u.reg_date, u.uptime, (SELECT AVG(uptime) AS avguptime FROM uptime u3 WHERE u3.username=u.username AND u3.machine=u.machine) AS avguptime, s.os, s.version, (SELECT c2.cpu FROM configurations c2 WHERE c2.fin_date IS NULL AND c2.username=u.username AND c2.machine=u.machine) AS cpu FROM uptime u, subversions s, machines m WHERE u.reg_date=(SELECT urs.max_reg_date FROM uptime_regdate_stats urs WHERE urs.username=u.username AND urs.machine=u.machine) AND s.subversion=(SELECT c.subversion FROM configurations c WHERE fin_date IS NULL AND c.username=u.username AND c.machine=u.machine) AND m.name=u.machine AND m.username=u.username AND m.active='t' ORDER BY u.uptime DESC;";
$bd->query($sQuery);

if ($bd->getErrDescr()!="Ok")
  echo("<TR><TD colspan=\"7\">Database ".$bd->getErrDescr()."</TD></TR>");
else
{
    $r=$bd->getResultatObj();
    if (count($r)>0)
    {
	$maxdif=0;
	foreach ($r as $k2 => $v2)
	{
	    $uptime_confirmat_v=$v2->uptime;
	    $uptime_teoric_v=theoreticalUptime($v2->uptime, $v2->reg_date);
	    $dif_uptime_v=$uptime_teoric_v-$uptime_confirmat_v;
	    
	    if ($dif_uptime_v>$maxdif)
	      $maxdif=$dif_uptime_v;		
	}
	
	
	$i=1;	
	foreach ($r as $k => $v)
	{
	    echo("<TR>");
	    echo("<TD class=\"celltaulafirst\">".$i."</TD>");

	    // validesa
	    
	    // maxim dif d'uptime es 1 - tots a escala
	    	    	    
	    $uptime_confirmat=$v->uptime;
	    $uptime_teoric=theoreticalUptime($v->uptime, $v->reg_date);
	    $dif_uptime=$uptime_teoric-$uptime_confirmat;
	    
	    /*$dif_uptime_escalada=$dif_uptime/$maxdif;
	    
	    $color_dif=round(255*$dif_uptime_escalada);
	    
	    $g=255-$color_dif;
	    $r=$color_dif;
	    $b=0;*/

	    $una_setmana=7*24*60*60;
	    $una_setmana=$v->avguptime;
	    
	    if ($dif_uptime<=$una_setmana)
	      $dif_uptime_escalada=$dif_uptime/$una_setmana;
	    else
	      $dif_uptime_escalada=1;
	    
	    $color_dif=round(255*$dif_uptime_escalada);

	    $g=255-$color_dif;
	    $r=$color_dif;
	    $b=0;
	    
	    $fiab=round((1-$dif_uptime_escalada)*100, 1);
	    	    
	    //$color_fons="#".dechex($r).dechex($g)."00";
	    
	    //echo("<TD class=\"celltaula\" bgcolor=\"".$color_fons."\">&nbsp;</TD>");
	    echo("<TD class=\"celltaula\"><IMG src=\"img.php?r=".$r."&amp;g=".$g."&amp;b=".$b."\" alt=\"\" title=\"Reliability: ".$fiab."%\" /></TD>");

	    echo("<TD class=\"celltaula\">".$v->machine."</TD>");
	    echo("<TD class=\"celltaula\">".$v->username."</TD>");
	    echo("<TD class=\"celltaula\">".niceUptime($v->uptime)."</TD>");
	    echo("<TD class=\"celltaula\">".niceUptime(theoreticalUptime($v->uptime, $v->reg_date))."</TD>");
	    echo("<TD class=\"celltaula\">".niceUptime(round($v->avguptime))."</TD>");
	    echo("<TD class=\"celltaula\">".$v->os." ".$v->version."</TD>");
	    echo("<TD class=\"celltaula\">".$v->cpu."</TD>");
	    echo("</TR>");

	    $i++;
	}
    }
}

?>
            	</table>
            	<p><br>
              	<br>

 	<p><br>
              	<br>
              	<br>
              	<span class="destacat"><br>
              	<br>
              	Machine ranking </span>(order by unconfirmed uptime)</p>
            	<p><br>
            	</p>
            	<table width="780" border="0" cellspacing="1" cellpadding="1">
              	<tr>
                	<td width="25" class="hdrtaula">Pos</td>
                	<td width="1" class="hdrtaula">&nbsp;</td>
                	<td width="105" class="hdrtaula">Machine</td>
                	<td width="63" class="hdrtaula">Owner</td>
                	<td width="134" class="hdrtaula">Confirmed Uptime</td>
                	<td width="134" class="hdrtaula">Unconfirmed Uptime</td>
                	<td width="105" class="hdrtaula">Avg</td>
                	<td width="126" class="hdrtaula">OS</td>
                	<td width="79" class="hdrtaula">Hardware</td>
              	</tr>

<?
//$bd=new bd;

$sQuery="SELECT u.username, u.machine, u.reg_date, u.uptime, ( uptime+(SELECT date_part('epoch', now()))-(SELECT date_part('epoch', reg_date))   ) AS uuptime, (SELECT AVG(uptime) AS avguptime FROM uptime u3 WHERE u3.username=u.username AND u3.machine=u.machine) AS avguptime, s.os, s.version, (SELECT c2.cpu FROM configurations c2 WHERE c2.fin_date IS NULL AND c2.username=u.username AND c2.machine=u.machine) AS cpu FROM uptime u, subversions s, machines m WHERE u.reg_date=(SELECT urs.max_reg_date FROM uptime_regdate_stats urs WHERE urs.username=u.username AND urs.machine=u.machine) AND s.subversion=(SELECT c.subversion FROM configurations c WHERE fin_date IS NULL AND c.username=u.username AND c.machine=u.machine) AND m.name=u.machine AND m.username=u.username AND m.active='t' ORDER BY uuptime DESC";
$bd->query($sQuery);

if ($bd->getErrDescr()!="Ok")
  echo("<TR><TD colspan=\"7\">Database ".$bd->getErrDescr()."</TD></TR>");
else
{
    $r=$bd->getResultatObj();
    if (count($r)>0)
    {
	$maxdif=0;
	foreach ($r as $k2 => $v2)
	{
	    $uptime_confirmat_v=$v2->uptime;
	    $uptime_teoric_v=theoreticalUptime($v2->uptime, $v2->reg_date);
	    $dif_uptime_v=$uptime_teoric_v-$uptime_confirmat_v;
	    
	    if ($dif_uptime_v>$maxdif)
	      $maxdif=$dif_uptime_v;		
	}

	$i=1;
	foreach ($r as $k => $v)
	{
	    echo("<TR>");
	    echo("<TD class=\"celltaulafirst\">".$i."</TD>");
	    
	    // validesa
	    
	    // maxim dif d'uptime es 1 - tots a escala
	    
	    $uptime_confirmat=$v->uptime;
	    $uptime_teoric=theoreticalUptime($v->uptime, $v->reg_date);
	    $dif_uptime=$uptime_teoric-$uptime_confirmat;
	    
	    /*$dif_uptime_escalada=$dif_uptime/$maxdif;
	    
	    $color_dif=round(255*$dif_uptime_escalada);
	    
	    $g=255-$color_dif;
	    $r=$color_dif;*/
	    
	    $una_setmana=7*24*60*60;
	    $una_setmana=$v->avguptime;
	    
	    if ($dif_uptime<=$una_setmana)
	      $dif_uptime_escalada=$dif_uptime/$una_setmana;
	    else
	      $dif_uptime_escalada=1;
	    
	    $color_dif=round(255*$dif_uptime_escalada);

	    $g=255-$color_dif;
	    $r=$color_dif;
	    $b=0;
	    
	    $fiab=round((1-$dif_uptime_escalada)*100, 1);
	    
	    //$color_fons="#".dechex($r).dechex($g)."00";
	    
	    //echo("<TD class=\"celltaula\" bgcolor=\"".$color_fons."\">&nbsp;</TD>");
	    echo("<TD class=\"celltaula\"><IMG src=\"img.php?r=".$r."&amp;g=".$g."&amp;b=".$b."\" alt=\"\" title=\"Reliability: ".$fiab."%\" /></TD>");
	    
	    echo("<TD class=\"celltaula\">".$v->machine."</TD>");
	    echo("<TD class=\"celltaula\">".$v->username."</TD>");
	    echo("<TD class=\"celltaula\">".niceUptime(round($v->uptime))."</TD>");
	    echo("<TD class=\"celltaula\">".niceUptime(round($v->uuptime))."</TD>");
	    echo("<TD class=\"celltaula\">".niceUptime(round($v->avguptime))."</TD>");
	    echo("<TD class=\"celltaula\">".$v->os." ".$v->version."</TD>");
	    echo("<TD class=\"celltaula\">".$v->cpu."</TD>");
	    echo("</TR>");

	    $i++;
	}
    }
}

?>
            	</table>
            	<p> <br>
              	<br>
              	<br>
              	<br>
              	<br>
              	<br>
              	<br>
              	<br>
              	<span class="destacat">Machine ranking </span>(order by avg uptime)</p>
            	<p><br>
            	</p>
            	<table width="780" border="0" cellspacing="1" cellpadding="1">
              	<tr>
                	<td width="25" class="hdrtaula">Pos</td>
                	<td width="1" class="hdrtaula">&nbsp;</td>
                	<td width="105" class="hdrtaula">Machine</td>
                	<td width="63" class="hdrtaula">Owner</td>
                	<td width="134" class="hdrtaula">Confirmed Uptime</td>
                	<td width="134" class="hdrtaula">Unconfirmed Uptime</td>
                	<td width="105" class="hdrtaula">Avg</td>
                	<td width="126" class="hdrtaula">OS</td>
                	<td width="79" class="hdrtaula">Hardware</td>
              	</tr>

<?
//$bd=new bd;

$sQuery="SELECT u.username, u.machine, u.reg_date, u.uptime, ( uptime+(SELECT date_part('epoch', now()))-(SELECT date_part('epoch', reg_date))   ) AS uuptime, (SELECT AVG(uptime) AS avguptime FROM uptime u3 WHERE u3.username=u.username AND u3.machine=u.machine) AS avguptime, s.os, s.version, (SELECT c2.cpu FROM configurations c2 WHERE c2.fin_date IS NULL AND c2.username=u.username AND c2.machine=u.machine) AS cpu FROM uptime u, subversions s, machines m WHERE u.reg_date=(SELECT urs.max_reg_date FROM uptime_regdate_stats urs WHERE urs.username=u.username AND urs.machine=u.machine) AND s.subversion=(SELECT c.subversion FROM configurations c WHERE fin_date IS NULL AND c.username=u.username AND c.machine=u.machine) AND m.name=u.machine AND m.username=u.username AND m.active='t' ORDER BY avguptime DESC";
$bd->query($sQuery);

if ($bd->getErrDescr()!="Ok")
  echo("<TR><TD colspan=\"7\">Database ".$bd->getErrDescr()."</TD></TR>");
else
{
    $r=$bd->getResultatObj();
    if (count($r)>0)
    {
	$maxdif=0;
	foreach ($r as $k2 => $v2)
	{
	    $uptime_confirmat_v=$v2->uptime;
	    $uptime_teoric_v=theoreticalUptime($v2->uptime, $v2->reg_date);
	    $dif_uptime_v=$uptime_teoric_v-$uptime_confirmat_v;
	    
	    if ($dif_uptime_v>$maxdif)
	      $maxdif=$dif_uptime_v;		
	}	
	
	$i=1;
	foreach ($r as $k => $v)
	{
	    echo("<TR>");
	    echo("<TD class=\"celltaulafirst\">".$i."</TD>");
	    
	    // validesa
	    
	    // maxim dif d'uptime es 1 - tots a escala
	    
	    $uptime_confirmat=$v->uptime;
	    $uptime_teoric=theoreticalUptime($v->uptime, $v->reg_date);
	    $dif_uptime=$uptime_teoric-$uptime_confirmat;
	    
	    /*$dif_uptime_escalada=$dif_uptime/$maxdif;
	    
	    $color_dif=round(255*$dif_uptime_escalada);
	    
	    $g=255-$color_dif;
	    $r=$color_dif;*/
	    
	    $una_setmana=7*24*60*60;
	    $una_setmana=$v->avguptime;
	    
	    if ($dif_uptime<=$una_setmana)
	      $dif_uptime_escalada=$dif_uptime/$una_setmana;
	    else
	      $dif_uptime_escalada=1;
	    
	    $color_dif=round(255*$dif_uptime_escalada);

	    $g=255-$color_dif;
	    $r=$color_dif;
	    $b=0;
	    
	    $fiab=round((1-$dif_uptime_escalada)*100, 1);
	    
	    //$color_fons="#".dechex($r).dechex($g)."00";
	    
	    //echo("<TD class=\"celltaula\" bgcolor=\"".$color_fons."\">&nbsp;</TD>");
	    echo("<TD class=\"celltaula\"><IMG src=\"img.php?r=".$r."&amp;g=".$g."&amp;b=".$b."\" alt=\"\" title=\"Reliability: ".$fiab."%\" /></TD>");
	    
	    echo("<TD class=\"celltaula\">".$v->machine."</TD>");
	    echo("<TD class=\"celltaula\">".$v->username."</TD>");
	    echo("<TD class=\"celltaula\">".niceUptime(round($v->uptime))."</TD>");
	    echo("<TD class=\"celltaula\">".niceUptime(round($v->uuptime))."</TD>");
	    echo("<TD class=\"celltaula\">".niceUptime(round($v->avguptime))."</TD>");
	    echo("<TD class=\"celltaula\">".$v->os." ".$v->version."</TD>");
	    echo("<TD class=\"celltaula\">".$v->cpu."</TD>");
	    echo("</TR>");

	    $i++;
	}
    }
}

?>
            	</table>
            	<p>
              	<br>

              	<br>
              	<br>
              	<br>
              	<br>
              	<br>
              	<br>
              	<br>
              	<br>
              	<br>
              	<br>
              	<br>
              	<br>
              	<br>
              	<br>
              	<br>
              	<br>
              	<br>
              	<br>
              	<br>
              	<br>
              	<br>
              	<br>
              	<br>
              	<br>
              	<br>
            	</p>
		<DIV align="right">
      	<a href="http://validator.w3.org/check?uri=referer"><img border="0"
          	src="http://www.w3.org/Icons/valid-html401"
          	alt="Valid HTML 4.01!" height="31" width="88"></a>
    	</DIV>
            	<p>&nbsp;</p></td>
        	</tr>
      	</table>

    	</td>
  	</tr>
	</table>
	</body>
	</html>
